// 数据同步相关的getters
export default {
  // 获取是否正在同步
  isSyncing: state => state.isSyncing,
  
  // 获取同步详细状态
  syncStatus: state => state.syncStatus,
  
  // 获取同步历史
  syncHistory: state => state.syncHistory,
  
  // 获取加载状态
  loading: state => state.loading,
  
  // 获取错误信息
  error: state => state.error,
  
  // 获取同步进度
  progress: state => state.progress,
  
  // 获取最后同步时间
  lastSyncTime: state => state.lastSyncTime,
  
  // 检查是否有同步历史
  hasSyncHistory: state => state.syncHistory.length > 0,
  
  // 获取同步历史记录数量
  syncHistoryCount: state => state.syncHistory.length,
  
  // 获取最新的同步历史记录
  latestSyncRecord: state => state.syncHistory[0] || null,
  
  // 获取成功的同步记录
  successfulSyncRecords: state => state.syncHistory.filter(record => record.status === 'completed'),
  
  // 获取失败的同步记录
  failedSyncRecords: state => state.syncHistory.filter(record => record.status === 'failed'),
  
  // 获取同步进度百分比文本
  progressText: state => `${state.progress}%`,
  
  // 格式化最后同步时间
  formattedLastSyncTime: state => {
    if (!state.lastSyncTime) return '从未同步'
    
    const date = new Date(state.lastSyncTime)
    const now = new Date()
    const diffMs = now - date
    const diffMins = Math.floor(diffMs / 60000)
    const diffHours = Math.floor(diffMs / 3600000)
    const diffDays = Math.floor(diffMs / 86400000)
    
    if (diffMins < 1) {
      return '刚刚同步'
    } else if (diffMins < 60) {
      return `${diffMins}分钟前同步`
    } else if (diffHours < 24) {
      return `${diffHours}小时前同步`
    } else if (diffDays < 7) {
      return `${diffDays}天前同步`
    } else {
      return date.toLocaleDateString()
    }
  },
  
  // 获取同步状态文本
  syncStatusText: state => {
    if (state.isSyncing) {
      if (state.syncStatus && state.syncStatus.currentOperation) {
        return `正在同步: ${state.syncStatus.currentOperation}`
      }
      return '正在同步数据...'
    } else if (state.syncStatus && state.syncStatus.status === 'completed') {
      return '同步完成'
    } else if (state.syncStatus && state.syncStatus.status === 'failed') {
      return '同步失败'
    } else {
      return '未在同步'
    }
  },
  
  // 获取同步状态图标
  syncStatusIcon: state => {
    if (state.isSyncing) {
      return 'loading'
    } else if (state.syncStatus && state.syncStatus.status === 'completed') {
      return 'success'
    } else if (state.syncStatus && state.syncStatus.status === 'failed') {
      return 'error'
    } else {
      return 'default'
    }
  }
}